package com.tensquare.sma.listener;

import com.aliyuncs.exceptions.ClientException;
import com.tensquare.sma.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zhc
 * @create 2019-04-15  21:15
 */
@Component
@RabbitListener(queues = "sms")
public class SmsRabbit {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${aliyun.sms.template_code}")
    private String template_code;
    @Value("${aliyun.sms.sign_name}")
    private String sign_name;

    @RabbitHandler
    public void executeSms(Map<String,Object> map){
        String modile=(String) map.get("modile");
        String checkcode=(String) map.get("checkcode");

        System.out.println("手机号"+map.get("modile"));
        System.out.println("验证码"+map.get("checkcode"));
        System.out.println(template_code);
        System.out.println(sign_name);

        try {
            smsUtil.sendSms(modile,template_code,sign_name,"{\"chcekcode\":\""+checkcode+"\"}");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }

}
